#!/usr/bin/env processtap
# -*- python -*-

import sys, os

include("stdio.h")
include("stdlib.h")

print os.getpid()
print hex(symbol("malloc"))
raw_input()

@syscall_entry()
def fentry(ctx):
    # FIXME: Must always use the extended slice syntax, otherwise 'start' and
    # 'stop' attributes of the slice object are truncated to int
    print ">>>", ctx.module, ctx.syscall, hex(ctx.regs.RSP), hex(ctx.regs.RIP), repr(ctx.mem[ctx.regs.RIP:ctx.regs.RIP+10:1])

@syscall_exit()
def fexit(ctx):
    print "<<<", ctx.module, ctx.syscall
    
#@memory_read()
#def wrap_mem_read(ctx, env):
#    print "mem_read", hex(ctx.address)

#@memory_write(size = 1)
#def wrap_mem_write(ctx, env):
#    print "mem_write"
